import defaultSettings from '@/settings'
import Cookies from 'js-cookie'
import _ from 'lodash'

const { theme , layout,  showSettings, tagsView, fixedHeader, sidebarLogo } = defaultSettings

const state = {
    theme: theme,
    layout: layout,
    showSettings: showSettings,
    tagsView: tagsView,
    fixedHeader: fixedHeader,
    sidebarLogo: sidebarLogo
}

const mutations = {
    CHANGE_SETTING: (state, { key, value }) => {
        if (state.hasOwnProperty(key)) {
            state[key] = value
        }
    }
}

const actions = {
    
    changeSetting({ commit }, data) {
        
        commit('CHANGE_SETTING', data)

        if(data.key==="theme"){
            localStorage.setItem( "CM-Admin-setting" , JSON.stringify(data))
        }else if(data.key==="layout"){
            localStorage.setItem( "CM-Admin-setting-layout" , JSON.stringify(data))
        }

    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}

